home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1994-09-04 | 17.5 KB | 669 lines |
- This application is FreeWare. (c) 1994 Dick Alstein
- initialize
- error
- QuitProgram%=
- 2PollMask%=(1<<0)+(1<<4)+(1<<5)+(1<<11)+(1<<12)
- "Wimp_Poll",PollMask%,PollBlk%
- ReasonCode%
- ReasonCode%
- 0 :
- Null_Event
- $
- ShiftAct%)
- -1)
- .
- Active%
- 1<<0
- update_wininfo
- /
- Active%
- 1<<1
- update_iconinfo
- .
- Active%
- 1<<2
- update_ptrinfo
-
- #
- 2 :
- Open_Window_Request
- (
- "Wimp_OpenWindow",,PollBlk%
- $
- 3 :
- Close_Window_Request
- )
- "Wimp_CloseWindow",,PollBlk%
-
- PollBlk%!0
-
- WinInfoWindow%
-
- setactive(0,
-
- IconInfoWindow%
-
- setactive(1,
-
- PtrInfoWindow%
-
- setactive(2,
-
- 6 :
- Mouse_Click
-
- mouseclick(PollBlk%)
- 8 :
- Key_Pressed
- *
- "Wimp_ProcessKey",PollBlk%!24
- 9 :
- Menu_Selection
-
- menuselect(PollBlk%)
- "7
- 17,18 :
- User_Message, User_Message_Recorded
-
- receive(PollBlk%)
- QuitProgram%
- "Wimp_CloseDown"
- --- END OF MAIN PROGRAM ---
- *** Close a window
- IN handle% = window to be closed
- closewindow(handle%)
- ScrapBlk%!0=handle%
- "Wimp_CloseWindow",,ScrapBlk%
- *** Pop up an error box
- IN err$ = error text
- cancel% = if <>0 then make 'Cancel' button, otherwise only 'OK'
- OUT TRUE if user clicked 'OK' button
- errbox(err$,cancel%)
- flags%
- ErrorBlk%!0=0
- $(ErrorBlk%+4)=err$+
- cancel%
- flags%=3
- flags%=1
- "Wimp_ReportError",err$,flags%,ApplName$
- ,click%
- =(click%=1)
- *** Error handling procedure
- Reports error, and quits program if user clicks 'Cancel'
- error
- "Wimp_CloseDown" :
- errbox(
- $+" (line "+
- )+")",
- clicked 'Cancel' - quit immediately
- "Wimp_CloseDown"
- *** Create an icon on the icon bar
- icon type is sprite-only, non-indirected
- the sprite is supposed to be in the Wimp sprite area
- IN spritename$ = name of sprite
- OUT number of the icon
- iconbaricon(spritename$)
- iconhandle%
- Y<ScrapBlk%!0=-1 :
- window handle = icon bar
- Z8ScrapBlk%!4=0 :
- minimum X coordinate
- [*ScrapBlk%!8=0 :
- min. Y
- \*ScrapBlk%!12=68 :
- max. X
- ]*ScrapBlk%!16=68 :
- max. Y
- ^.ScrapBlk%!20=&7000301A :
- icon flags
- _2$(ScrapBlk%+24)=spritename$ :
- name of sprite
- "Wimp_CreateIcon",,ScrapBlk%
- iconhandle%
- =iconhandle%
- *** Indicates if a certain icon has been selected
- IN window% = handle of the window
- icon% = number of the icon
- OUT TRUE if icon is selected, FALSE if not selected
- iconselected(window%,icon%)
- ScrapBlk%!0=window%
- ScrapBlk%!4=icon%
- "Wimp_GetIconState",,ScrapBlk%
- l#=((ScrapBlk%!24)
- (1<<21)) > 0
- *** Initialize all the necessary stuff
- initialize
- ApplName$="WimpInfo"
- ApplDir$="<WimpInfo$Dir>"
- s"ApplVersion$="1.00 (4-Sep-94)"
- ErrorBlk% 256 :
- block for error data
- "Wimp_Initialise",200,&4B534154,ApplName$
- OSversion%,MyTaskHandle%
- error
- ScrapBlk% 256 :
- general-purpose memory block
- WorkBlk% 2048 :
- memory block for storing larger data
- PollBlk% 256 :
- memory block for data from Wimp_Poll
- z'IbarIcon%=
- iconbaricon("!WimpInfo")
- {PIndirsize%=1200 :
- size of indirected data for template windows
- Indir% Indirsize% :
- buffer for indirected data
- }IIndirend%=Indir%+Indirsize% :
- address after last byte of indirected
- IconBType$(15) :
- names of icon button types
- WinBType$(15) :
- names of window button types
- IconBType$(0)="Never"
- IconBType$(1)="Always"
- IconBType$(2)="Auto-repeat"
- IconBType$(3)="Click"
- IconBType$(4)="Release"
- IconBType$(5)="Double click"
- IconBType$(6)="Click/Drag"
- IconBType$(7)="Release/Drag"
- IconBType$(8)="Double/Drag"
- IconBType$(9)="Menu"
- &IconBType$(10)="Double/Click/Drag"
- IconBType$(11)="Radio"
- "IconBType$(12)="12 (reserved)"
- "IconBType$(13)="13 (reserved)"
- %IconBType$(14)="Write/Click/Drag"
- IconBType$(15)="Writable"
- WinBType$(0)="Never"
- WinBType$(1)="Always"
- WinBType$(2)="Auto-repeat"
- WinBType$(3)="Click"
- WinBType$(4)="Release"
- WinBType$(5)="Double click"
- WinBType$(6)="Click/Drag"
- WinBType$(7)="Release/Drag"
- WinBType$(8)="Double/Drag"
- WinBType$(9)="Click"
- %WinBType$(10)="Double/Click/Drag"
- WinBType$(11)="Click/Drag"
- !WinBType$(12)="12 (reserved)"
- !WinBType$(13)="13 (reserved)"
- !WinBType$(14)="14 (reserved)"
- WinBType$(15)="Writable"
- load the templates and create windows with it
- "Wimp_OpenTemplate",,ApplDir$+".Templates"
- %InfoWindow%=
- loadtemplate("Info")
- .WinInfoWindow%=
- loadtemplate("WindowInfo")
- -IconInfoWindow%=
- loadtemplate("IconInfo")
- +PtrInfoWindow%=
- loadtemplate("PtrInfo")
- "Wimp_CloseTemplate"
- seticontext(InfoWindow%,7,ApplVersion$)
- "MenuUtil_Initialise",010,0 :
- initialise MenuUtils module
- initmenus
- readscreenvars
- Active%=0
- LastActive%=1<<1
- ShiftAct%=
- *** Construct the menus
- initmenus
- "MainMenu%=
- menu_new(ApplName$)
- 0Item_Info%=
- menu_add("Info",InfoWindow%,1,0)
- 1Item_WinInfo%=
- menu_add("Window info",-1,0,0)
- 0Item_IconInfo%=
- menu_add("Icon info",-1,0,0)
- 0Item_PtrInfo%=
- menu_add("Mouse info",-1,1,0)
- 6Item_ShiftAct%=
- menu_add("Shift-activated",-1,0,0)
- 'Item_Quit%=
- menu_add("Quit",-1,0,0)
- *** Load a template definition and create a window with it
- IN name$ = name of template
- OUT window handle of created window
- loadtemplate(name$)
- handle%
- "Wimp_CloseTemplate" :
- error
- "Wimp_LoadTemplate",,WorkBlk%+4,Indir%,Indirend%,-1,name$,0
- ,,Indir%
- "Wimp_CreateWindow",,WorkBlk%+4
- handle%
- =handle%
- *** Add an item to the current menu
- IN text$ = text of item
- submenu% = submenu -
- -1 if no submenu attached to this item
- menu handle if normal submenu
- window handle if submenu is a window
- dotline% = if <> 0 then draw dotted line below item
- genmsg% = if <> 0 then Wimp generates message if submenu opened
- OUT handle of new item
- menu_add(text$,submenu%,dotline%,genmsg%)
- handle%
- "MenuUtil_Add",,text$
- handle%
- submenu%<>-1
- "MenuUtil_SubMenu",handle%,submenu%
- dotline%
- "MenuUtil_Dots",,1
- genmsg%
- "MenuUtil_Warning",handle%,1
- =handle%
- *** Add a writable item to the current menu
- IN maxlen% = maximum string length of the writable item
- validstr% = pointer to validation string (or 0 for no validation)
- OUT handle of new item
- menu_addwritable(maxlen%,validstr%)
- handle%
- "MenuUtil_Add",,""
- handle%
- "MenuUtil_Writable",,1,maxlen%,validstr%
- =handle%
- *** Create a new menu and make it the current menu
- IN title$ = menu title
- OUT handle of new menu
- menu_new(title$)
- handle%
- "MenuUtil_New",,title$
- handle%
- =handle%
- *** Show a menu on the screen
- IN menu% = handle of menu to be shown
- buffer% = pointer to block with mouse event (as returned by Wimp_Poll)
- or 0 to redisplay last menu
- menu_show(menu%,buffer%)
- "MenuUtil_Show",menu%,buffer%
- *** Process menu selection event
- menuselect(selection%)
- adjust%,selinfo%,item%,item$,parentitem%
- "MenuUtil_Decode",MainMenu%,selection%
- ,adjust%,selinfo%
- 8item%=selinfo%!8 :
- handle of selected item
- 5item$=
- str(selinfo%!12) :
- text of selected item
- Dparentitem%=selinfo%!24 :
- handle of 'parent' of selected item
- item%
- Item_WinInfo%
- *
- setactive(0,(Active%
- 1<<0)=0,
- Item_IconInfo%
- *
- setactive(1,(Active%
- 1<<1)=0,
- Item_PtrInfo%
- *
- setactive(2,(Active%
- 1<<2)=0,
- Item_ShiftAct%
- ShiftAct%=
- ShiftAct%
- 3
- "MenuUtil_Tick",Item_ShiftAct%,ShiftAct%
- Item_Quit%
- QuitProgram%=
- adjust%
- menu_show(MainMenu%,0)
- *** Process mouse click event
- IN buffer% = pointer to buffer containing click event data
- mouseclick(buffer%)
- button%,window%,icon%
- =button%=PollBlk%!8 :
- mouse button(s) that were pressed
- >window%=PollBlk%!12 :
- handle of window that click was in
- <icon%=PollBlk%!16 :
- number of icon that click was on
- window%
- button%
-
- 2 :
- Menu button
- )
- menu_show(MainMenu%,buffer%)
-
- 4 :
- Select button
- .
- setactive(0,LastActive%
- 1<<0,
- .
- setactive(1,LastActive%
- 1<<1,
- !.
- setactive(2,LastActive%
- 1<<2,
-
- 1 :
- Adjust button
- LastActive%=Active%
-
- setactive(0,
-
- setactive(1,
-
- setactive(2,
- '
- *** Open a window at the screen position where it last was
- window is opened 'on top'
- IN handle% = window to be opened
- openwindow(handle%)
- ScrapBlk%!0=handle%
- "Wimp_GetWindowState",,ScrapBlk%
- ScrapBlk%!28=-1
- "Wimp_OpenWindow",,ScrapBlk%
- *** Read the dimensions of the current screen mode and store it in variables
- OUT Screensize_X% = horizontal screen size in OS units
- Screensize_Y% = vertical screen size in OS units
- readscreenvars
- xeig%,yeig%,xpixels%,ypixels%
- "OS_ReadModeVariable",-1,4
- ,,xeig%
- "OS_ReadModeVariable",-1,5
- ,,yeig%
- "OS_ReadModeVariable",-1,11
- ,,xpixels%
- "OS_ReadModeVariable",-1,12
- ,,ypixels%
- @)Screensize_X%=(xpixels%+1)*(1<<xeig%)
- A)Screensize_Y%=(ypixels%+1)*(1<<yeig%)
- *** Process incoming messages
- receive(buffer%)
- sender%,senderref%,code%,ack%
- H6sender%=buffer%!4 :
- task handle of the sender
- I>senderref%=buffer%!8 :
- reference number for this message
- J)code%=buffer%!16 :
- message code
- K>ack%=0 :
- must we acknowledge this message?
- sender% <> MyTaskHandle%
- code%
- N0
- 0 :
- Message_Quit - program must quit
- QuitProgram%=
- P?
- &400C1 :
- Message_ModeChange - Wimp mode has changed
-
- readscreenvars
- ack%<>0
- ScrapBlk%!0=256
- ScrapBlk%!12=senderref%
- ScrapBlk%!16=ack%
- W2
- "Wimp_SendMessage",17,ScrapBlk%,sender%
- *** Select or un-select an icon
- IN window% = handle of the window
- icon% = number of the icon
- flag% = if not zero then select the icon, if zero then un-select it
- selecticon(window%,icon%,flag%)
- oldflag%
- ScrapBlk%!0=window%
- ScrapBlk%!4=icon%
- "Wimp_GetIconState",,ScrapBlk%
- f%oldflag%=(ScrapBlk%!24)
- (1<<21)
- flag%
- ScrapBlk%!8=1<<21
- ScrapBlk%!8=0
- ScrapBlk%!12=1<<21
- oldflag%<>ScrapBlk%!8
- only set when changing
- "Wimp_SetIconState",,ScrapBlk%
- *** Set the "active" state of one of the infos
- IN no% = number
- switch% = if not zero then make active, if zero then make inactive
- store% = if not zero then store new state in variable LastActive%
- setactive(no%,switch%,store%)
- window%,item%
- no%
- window%=WinInfoWindow%
- item%=Item_WinInfo%
- window%=IconInfoWindow%
- item%=Item_IconInfo%
- window%=PtrInfoWindow%
- item%=Item_PtrInfo%
- switch%
- Active%=Active%
- (1<<no%)
- openwindow(window%)
- ! Active%=Active%
- (1<<no%)
- closewindow(window%)
- store%
- LastActive%=Active%
- "MenuUtil_Tick",item%,Active%
- (1<<no%)
- Active%
- ! PollMask%=PollMask%
- PollMask%=PollMask%
- *** Set the text in an icon
- IN window% = handle of the window
- icon% = number of the icon
- text$ = new contents
- seticontext(window%,icon%,text$)
- ptr%,length%,oldtext$
- ScrapBlk%!0=window%
- ScrapBlk%!4=icon%
- "Wimp_GetIconState",,ScrapBlk%
- first check the icon flags to see if it's an indirected-text icon
- (ScrapBlk%!24
- &101)=&101
- ; length%=ScrapBlk%!36 :
- max. size of indirected data
- oldtext$=$(ScrapBlk%!28)
- text$<>oldtext$
- D
- overwrite old text, restricting the length of the new text
- K $(ScrapBlk%!28)=
- text$,length%-1) :
- "length%-1" - Basic adds a CR
- ,
- then update the icon on the screen
- ScrapBlk%!8=0
- ScrapBlk%!12=0
- )
- "Wimp_SetIconState",,ScrapBlk%
- *** Read a zero-terminated string from memory
- IN ptr% = pointer to string
- OUT string
- str(ptr%)
- i%,s$
- (ptr%?i%>=32)
- (i%<255)
- s$+=
- (ptr%?i%)
- i%+=1
- *** Update the Window Info window
- update_wininfo
- window%,icon%,flags%,taskid%,taskname%,taskname$,fullsize%
- "Wimp_GetPointerInfo",,WorkBlk%
- window%=WorkBlk%!12
- icon%=WorkBlk%!16
- window%<0
- seticontext(WinInfoWindow%,4,
- (window%))
- seticontext(WinInfoWindow%,4,"&"+
- ~(window%))
- WorkBlk%!0=window%
- OSversion%<300
- "Wimp_GetWindowInfo",,WorkBlk%
- "Wimp_GetWindowInfo",,WorkBlk%+1
- flags%=WorkBlk%!32
- seticontext(WinInfoWindow%,5,"&"+
- ~(flags%))
- seticontext(WinInfoWindow%,6,WinBType$((WorkBlk%!64)>>12
- &F))
- seticontext(WinInfoWindow%,7,"&"+
- ~(WorkBlk%!60))
- seticontext(WinInfoWindow%,10,
- (WorkBlk%!56))
- seticontext(WinInfoWindow%,11,
- (WorkBlk%!44))
- seticontext(WinInfoWindow%,12,
- (WorkBlk%!52))
- seticontext(WinInfoWindow%,13,
- (WorkBlk%!48))
- seticontext(WinInfoWindow%,16,
- (WorkBlk%!16))
- seticontext(WinInfoWindow%,17,
- (WorkBlk%!4))
- seticontext(WinInfoWindow%,18,
- (WorkBlk%!12))
- seticontext(WinInfoWindow%,19,
- (WorkBlk%!8))
- seticontext(WinInfoWindow%,23,
- (WorkBlk%!20))
- seticontext(WinInfoWindow%,24,
- (WorkBlk%!24))
- taskname$=""
- OSversion%>=300
- send the owner task a dummy acknowledge, just to get the taskhandle
- WorkBlk%!0=256
- WorkBlk%!12=0
- WorkBlk%!16=0
- "Wimp_SendMessage",19,WorkBlk%,window%,icon%
- ,,taskid%
- "XTaskManager_TaskNameFromHandle",taskid%
- taskname%;flg%
- (flg%
- 1)=0
- ! taskname$=
- str(taskname%)
- seticontext(WinInfoWindow%,38,taskname$)
- WorkBlk%!0=WinInfoWindow%
- "Wimp_GetWindowState",,WorkBlk%
- )fullsize%=((WorkBlk%!32)
- (1<<18))<>0
- fullsize%
- selecticon(WinInfoWindow%,25,flags%
- 1<<1)
- selecticon(WinInfoWindow%,26,flags%
- 1<<4)
- selecticon(WinInfoWindow%,27,flags%
- 1<<5)
- selecticon(WinInfoWindow%,28,flags%
- 1<<6)
- selecticon(WinInfoWindow%,29,flags%
- 1<<8)
- selecticon(WinInfoWindow%,30,flags%
- 1<<9)
- selecticon(WinInfoWindow%,31,flags%
- 1<<10)
- selecticon(WinInfoWindow%,32,flags%
- 1<<11)
- selecticon(WinInfoWindow%,33,flags%
- 1<<12)
- selecticon(WinInfoWindow%,34,flags%
- 1<<13)
- selecticon(WinInfoWindow%,35,flags%
- 1<<14)
- selecticon(WinInfoWindow%,36,flags%
- 1<<15)
- *** Update the Icon Info window
- update_iconinfo
- window%,icon%,flags%,fullsize%
- "Wimp_GetPointerInfo",,WorkBlk%
- window%=WorkBlk%!12
- icon%=WorkBlk%!16
- WorkBlk%!0=window%
- WorkBlk%!4=icon%
- window%<0
- seticontext(IconInfoWindow%,3,
- (window%))
- seticontext(IconInfoWindow%,3,"&"+
- ~(window%))
- seticontext(IconInfoWindow%,4,
- (icon%))
- icon%>=0
- "Wimp_GetIconState",,WorkBlk%
- flags%=WorkBlk%!24
- seticontext(IconInfoWindow%,5,"&"+
- ~(WorkBlk%!24))
- seticontext(IconInfoWindow%,8,
- (WorkBlk%!20))
- seticontext(IconInfoWindow%,9,
- (WorkBlk%!8))
- seticontext(IconInfoWindow%,10,
- (WorkBlk%!16))
- seticontext(IconInfoWindow%,11,
- (WorkBlk%!12))
- seticontext(IconInfoWindow%,14,IconBType$((flags%>>12)
- &F))
- seticontext(IconInfoWindow%,15,
- ((flags%>>16)
- &1F))
- icon%=-4
- WorkBlk%!0=window%
- OSversion%<300
- +
- "Wimp_GetWindowInfo",,WorkBlk%
-
- -
- "Wimp_GetWindowInfo",,WorkBlk%+1
-
- flags%=WorkBlk%!60
- flags%=0
- seticontext(IconInfoWindow%,5,"")
- seticontext(IconInfoWindow%,8,"")
- seticontext(IconInfoWindow%,9,"")
- seticontext(IconInfoWindow%,10,"")
- seticontext(IconInfoWindow%,11,"")
- seticontext(IconInfoWindow%,14,"")
- seticontext(IconInfoWindow%,15,"")
- WorkBlk%!0=IconInfoWindow%
- "Wimp_GetWindowState",,WorkBlk%
- *)fullsize%=((WorkBlk%!32)
- (1<<18))<>0
- fullsize%
- selecticon(IconInfoWindow%,16,flags%
- 1<<0)
- selecticon(IconInfoWindow%,17,flags%
- 1<<1)
- selecticon(IconInfoWindow%,18,flags%
- 1<<2)
- selecticon(IconInfoWindow%,19,flags%
- 1<<3)
- selecticon(IconInfoWindow%,20,flags%
- 1<<4)
- selecticon(IconInfoWindow%,21,flags%
- 1<<5)
- selecticon(IconInfoWindow%,22,flags%
- 1<<6)
- selecticon(IconInfoWindow%,23,flags%
- 1<<7)
- selecticon(IconInfoWindow%,24,flags%
- 1<<8)
- selecticon(IconInfoWindow%,25,flags%
- 1<<9)
- selecticon(IconInfoWindow%,26,flags%
- 1<<10)
- selecticon(IconInfoWindow%,27,flags%
- 1<<11)
- selecticon(IconInfoWindow%,28,flags%
- 1<<21)
- *** Update the Pointer Info window
- update_ptrinfo
- "Wimp_GetPointerInfo",,WorkBlk%
- seticontext(PtrInfoWindow%,3,
- (WorkBlk%!0))
- seticontext(PtrInfoWindow%,4,
- (WorkBlk%!4))
- seticontext(PtrInfoWindow%,5,
- (WorkBlk%!8))
-